Skip to content

fix(client): bump HTTP timeout 1.5s → 5s, REFUSE_TIMEOUT_MS override#27

Open
gok03 wants to merge 2 commits into
mainfrom
fix/client-timeout
Open

fix(client): bump HTTP timeout 1.5s → 5s, REFUSE_TIMEOUT_MS override#27
gok03 wants to merge 2 commits into
mainfrom
fix/client-timeout

Conversation

@gok03
Copy link
Copy Markdown
Contributor

@gok03 gok03 commented May 19, 2026

Symptom

Users on slow / high-latency networks see every gate call fail with:

```
refuse: server: unreachable: Post "https://mcp.refuse.dev/api/v1/check/batch\":
context deadline exceeded (Client.Timeout exceeded while awaiting headers)
```

even though the server is healthy (`/healthz` returns 200 in ~600ms when curl'd from a fast network).

Root cause

`internal/server/client.go` hardcoded `Timeout: 1500 * time.Millisecond`. Any RTT > 1.5s (hotel Wi-Fi, cellular, cold-start TLS handshake) trips it.

Fix

  • Default timeout bumped to 5s. Still feels interactive at the terminal; survives normal jitter.
  • New env var `REFUSE_TIMEOUT_MS` for users who want to tune further (CI might want longer, a sub-second-RTT network might want shorter).
  • README documents both the new env var and `REFUSE_NO_GATE` (which already existed but wasn't surfaced anywhere).

Test plan

  • CI green
  • User on the slow network confirms `pip install requests` no longer prints "server: unreachable"
  • `REFUSE_TIMEOUT_MS=100 pip install requests` does print "unreachable" (smoke-test that the override works)

gok03 added 2 commits May 19, 2026 20:49
…rride

The hardcoded 1.5s HTTP timeout was too tight for real-world networks:
hotel Wi-Fi, long-RTT links, or any path where TLS handshake + first
byte stretches past 1.5s would see every gate call fail open with a
"server: unreachable" line in stderr.

Bump the default to 5s (still a clearly-interactive feel — a user
typing `pip install foo` won't notice an extra ~half-second on a slow
network, but will appreciate not seeing the gate fail) and expose a
REFUSE_TIMEOUT_MS env var for users who want to tune it further.

README documents both the new env var and REFUSE_NO_GATE (which already
existed in shim/run.go but wasn't documented).
Measured mcp.refuse.dev latency: first request after idle is ~4.6s
(scale-from-zero cold start), then 0.2–0.4s warm. A 5s default left only
~0.4s margin over the cold start; bump to 8s so the first install after
an idle period doesn't fail open with a "server: unreachable" warning.
Still fails reasonably fast when the server is genuinely down, and
REFUSE_TIMEOUT_MS overrides for anyone who wants tighter/looser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant